﻿Public Class frmEditions
    Public pRubrique As String

    Private szSQL As String
    Private rs As ADODB.Recordset = Nothing

    Private Sub frmEditions_Load(sender As Object, e As System.EventArgs) Handles Me.Load
        Dim nb As Integer = 0

        ' effacer la listview
        LV_ETATS.Items.Clear()

        ' affiche les 50 CABINETS à partir de l'élève courant
        szSQL = "CALL spGET_P_EDITCRYS('RUBRIQUE','" & pRubrique & "')"
        GetRecordset(ctDSN_DEVFAC, szSQL, rs)

        ' Load the data.
        Do While Not rs.EOF
            LV_ETATS.Items.Add(rs.Fields("libelle").Value)
            LV_ETATS.Items(nb).SubItems.Add(rs.Fields("crystal_rpt").Value)
            LV_ETATS.Items(nb).SubItems.Add(nv(rs.Fields("procedure").Value))
            nb = nb + 1
            ' Get the next record
            rs.MoveNext()
        Loop
        ' Close the recordset AND connection.
        rs.Close()

        ' restaurer la position du curseur avant le init
        setIndice(0, LV_ETATS)

    End Sub

    Private Sub BO_IMPRIMER_Click(sender As System.Object, e As System.EventArgs)
        Call LV_ETATS_DoubleClick(sender, e)
    End Sub

    Private Sub LV_ETATS_DoubleClick(sender As Object, e As System.EventArgs) Handles LV_ETATS.DoubleClick

        ' un état est-il sélectionné ?
        If LV_ETATS.SelectedItems.Count <= 0 Then
            Exit Sub
        End If

        Dim dateRPT As String = LV_ETATS.SelectedItems(0).SubItems(2).Text
        Dim szNomRPT As String = LV_ETATS.SelectedItems(0).SubItems(1).Text

        Select Case szNomRPT
            Case "contrat"
                '    ' imprimer le contrat et ses annexes 
                '    EditerContrat(pParametres)
                '    ' ferme la fenetre
                '    Me.Close()

            Case "courrier"
                '    ' edition d'un courrier : selectionner un RPT du dossier /COURRIERS
                '    Dim openDataFileDialog As OpenFileDialog = New OpenFileDialog()
                '    openDataFileDialog.Filter = "Fichiers Crystal ou Word|*.rpt;*.doc"
                '    openDataFileDialog.InitialDirectory = Mid(My.Application.Info.DirectoryPath, 1, 10) & "\COURRIERS\"
                '    If openDataFileDialog.ShowDialog = Windows.Forms.DialogResult.OK Then
                '        szSQL = openDataFileDialog.FileName
                '    Else
                '        Exit Sub
                '    End If
                '    ' fichier RPT ou DOC
                '    If LCase(Mid(szSQL, szSQL.Length - 2, 3)) = "rpt" Then
                '        frmViewReport.pCodeEtat = noRPT
                '        frmViewReport.pParamRPT = szSQL   'contient le chemein du RPT séléctionné
                '        frmViewReport.ShowDialog()
                '    Else
                '        EditerWord(szSQL)
                '    End If

            Case Else ' édition d'un état ayant comme nom szNomRPT
                ' Sélection de DATES ?
                If dateRPT = "DATE" Then
                    frmDatesSelection.ShowDialog()
                    ' dates saisies ?
                    If frmDatesSelection.pSelection.Length > 0 Then
                        frmViewReport.pParamRPT = frmDatesSelection.pSelection
                    Else
                        Exit Sub
                    End If
                Else
                    frmViewReport.pParamRPT = ""
                End If

                ' édition de l'étatRPT
                frmViewReport.pNomEtat = szNomRPT
                frmViewReport.ShowDialog()

        End Select
        ' ferme la fenetre
        Me.Close()

    End Sub

    Private Sub LV_ETATS_KeyDown(sender As Object, e As System.Windows.Forms.KeyEventArgs) Handles LV_ETATS.KeyDown
        Select Case e.KeyCode
            Case Keys.Enter         ' Enter = DoubleClick
                LV_ETATS_DoubleClick(sender, e)
        End Select

    End Sub


End Class